/*
 * @Author: hpc(hepch)
 * @Date: 2021-06-02 11:21:47
 * @LastEditors: 何鹏程(hepch)
 * @LastEditTime: 2021-06-23 21:08:41
 * @Description:
 * @Copyright: 超图软件华中平台客户中心 (SuperMap Software Co., Ltd. -Central China Platform)
 */
import { get, post, axiosconfig, del, put } from "./http";

function getServerApis() {
  return get("./conf/serverApis.json");
}
const services = {
  /**
   * @description: 保存修改书签
   * @param {object} param
   * @return {promise} promise
   */

  getUserName: async function () {
    let promise = getServerApis();
    let servicesApis;
    console.log(promise);
    await promise.then((res) => {
      console.log(res.result.records);
      servicesApis = res.result.records;
    });
    let serverParam = servicesApis.userServer;
    let pathlist = serverParam.apiList;
    let serverUrl = window.getServiceUrl(
      pathlist.userName,
      window.servicesPorts.iportal
    );
    return get(serverUrl);
  },
  /**
   * @description: 保存修改书签
   * @param {object} param
   * @return {promise} promise
   */

  savebookMark: async function (param) {
    let promise = getServerApis();
    let servicesApis;
    console.log(promise);
    await promise.then((res) => {
      console.log(res.result.records);
      servicesApis = res.result.records;
    });
    let serverParam = servicesApis.bookMarkServer;
    let pathlist = serverParam.apiList;
    let serverUrl = window.getServiceUrl(
      pathlist.saveBookMark,
      window.servicesPorts.boot
    );
    return post(serverUrl, param);
  },
  editBookMark: async function (param) {
    let promise = getServerApis();
    let servicesApis;
    console.log(promise);
    await promise.then((res) => {
      console.log(res.result.records);
      servicesApis = res.result.records;
    });
    let serverParam = servicesApis.bookMarkServer;
    let pathlist = serverParam.apiList;
    let serverUrl = window.getServiceUrl(
      pathlist.editBookMark,
      window.servicesPorts.boot
    );
    return put(serverUrl, param);
  },

  /**
   * @description: 删除书签
   * @param {object} param
   * @return {promise} promise
   */
  removeBookMark: async function (param) {
    let promise = getServerApis();
    let servicesApis;
    console.log(promise);
    await promise.then((res) => {
      console.log(res.result.records);
      servicesApis = res.result.records;
    });
    let serverParam = servicesApis.bookMarkServer;
    let pathlist = serverParam.apiList;
    let serverUrl = window.getServiceUrl(
      pathlist.removeBookMark,
      window.servicesPorts.boot
    );
    return del(serverUrl, param);
  },
  /**
   * @description: 查询书签
   * @param {object} param
   * @return {promise} promise
   */
  querybookMark: async function (param) {
    let promise = getServerApis();
    let servicesApis;
    console.log(promise);
    await promise.then((res) => {
      console.log(res.result.records);
      servicesApis = res.result.records;
    });
    let serverParam = servicesApis.bookMarkServer;
    let pathlist = serverParam.apiList;
    let serverUrl = window.getServiceUrl(
      pathlist.queryBookMark,
      window.servicesPorts.boot
    );
    return get(serverUrl, param);
  },
  /**
   * @description: 车辆查询轨迹数据
   * @param {object} param
   * @return {promise} promise
   */
  searchVehicleTrack: async function (param) {
    let promise = getServerApis();
    let servicesApis;
    console.log(promise);
    await promise.then((res) => {
      console.log(res.result.records);
      servicesApis = res.result.records;
    });
    let serverParam = servicesApis.vehicleServer;
    let pathlist = serverParam.apiList;
    let headers = {
      SceneCode: "7115bc89e9b34020b53df79e431e1792",
    };
    //
    return get(
      serverParam.serverIp + ":" + serverParam.serverPort + pathlist.trackPath,
      param,
      headers
    );
  },
  /**
   * @description: 车辆查询定位数据
   * @param {object} param
   * @return {promise} promise
   */
  searchVehicleLocation: async function (param) {
    let promise = getServerApis();
    let servicesApis;
    await promise.then((res) => {
      console.log(res.result.records);
      servicesApis = res.result.records;
    });
    let serverParam = servicesApis.vehicleServer;
    let pathlist = serverParam.apiList;
    let headers = {
      SceneCode: "7115bc89e9b34020b53df79e431e1792",
    };
    return get(
      serverParam.serverIp +
        ":" +
        serverParam.serverPort +
        pathlist.locationPath,
      param,
      headers
    );
  },
  searchVehicleTypeLocation: async function (param) {
    let promise = getServerApis();
    let servicesApis;
    await promise.then((res) => {
      console.log(res.result.records);
      servicesApis = res.result.records;
    });
    let serverParam = servicesApis.vehicleServer;
    let pathlist = serverParam.apiList;
    let headers = {
      SceneCode: "7115bc89e9b34020b53df79e431e1792",
    };
    return get(
      serverParam.serverIp +
        ":" +
        serverParam.serverPort +
        pathlist.vehiclesLocationPath,
      param,
      headers
    );
  },
  searchVehicleInfo: async function (param) {
    let promise = getServerApis();
    let servicesApis;
    await promise.then((res) => {
      console.log(res.result.records);
      servicesApis = res.result.records;
    });
    let serverParam = servicesApis.vehicleinfoServer;
    let pathlist = serverParam.apiList;
    let headers = {};
    serverParam.esurl = window.getServiceUrl("", window.servicesPorts.es);
    return post(serverParam.esurl + pathlist.vehicleInfoPath, param, headers);
  },
  queryImages: async function () {
    let promise = getServerApis();
    let servicesApis;
    console.log(promise);
    await promise.then((res) => {
      console.log(res.result.records);
      servicesApis = res.result.records;
    });
    let serverParam = servicesApis.imageServer;
    let pathlist = serverParam.apiList;
    let data = new FormData();
    data.append(
      "data",
      '{"showprops":true,"props":[{"code":"servicetype","value":"xq","exists":true}]}'
    );
    data.append("p", '{"n":100}');
    var config = {
      method: "post",
      url: pathlist.xqimageApi,
      data: data,
    };
    return axiosconfig(config);
  },
};
export default services;
